/**
 * 产品修改js
 */
var comValidform=null;
var returnStatus=false;
var productInfoUpdate={
	dataCache:null,
	introduceUE:null,
	incomeUE:null,
	riskctrlUE:null,
		
	startEvent:function(){
		$("#recordTab ul").idTabs();
		productInfoUpdate.introduceUE = UE.getEditor('introduce',{
			initialFrameHeight:340,
			initialFrameWidth:898
		});
		productInfoUpdate.incomeUE = UE.getEditor('income',{
			initialFrameHeight:340,
			initialFrameWidth:898
		});
		productInfoUpdate.riskctrlUE = UE.getEditor('riskctrl',{
			initialFrameHeight:340,
			initialFrameWidth:898
		});
		
		productInfoUpdate.showInfoById();
		
		comValidform=$(".com-addForm").Validform({
			datatype:{
				"m0-2" : /^[0-9]+(.[0-9]{1,2})?$/
			},
			tiptype:2,
			tipSweep:true,
			beforeSubmit:function(curform){
				var url = 'mgr/ProductInfoCtrl/updateProductInfo';
				var params = jsUtils.serializeJson($('.com-addForm'));
				var introduce=productInfoUpdate.introduceUE.getContent();
				params.introduce=introduce;
				
				var income=productInfoUpdate.incomeUE.getContent();
				params.income=income;
				
				var riskctrl=productInfoUpdate.riskctrlUE.getContent();
				params.riskctrl=riskctrl;
				
				var cb = function(data){
					alert(data.msg);
					//成功返回
					if(data.resultCode==200){
						//关闭窗口并刷新数据
						art.dialog.close();
						returnStatus=true;
					}
				};
				sendApiNoLoadSync(url, params, cb, 'POST');
				return false;
			}
		});
	},
	
	showInfoById:function(){
		var updId=art.dialog.data('updId');  //修改id
		var url = 'mgr/ProductInfoCtrl/getProductInfoById';
		var params ={
				'id':updId
		};
		var cb = function(data){
			if(data.resultCode==200){
				var ret=data.result;
				for(var i in ret){
					var text=ret[i];
					if(i=='establishDate'||i=='onlineDate'||i=='endDate'||i=='releasesDate'||i=='balanceDate'||i=='discountDate'){
						text=text==null?'':(new Date(text)).format('yyyy-MM-dd');
					}else  if(i=='prodType'||i=='proTerm'||i=='publishType'||i=='riskLevel'||i=='currency'||i=='isOversea'||i=='discount'||i=='discountRate'){
						$('#com-addForm select[name="'+i+'"]').val(text);
						continue;
					}else if(i=='claimRecommendInfo'||i=='creditAssignmentInfo'|i=='paymentSource'||i=='remark'){
						$('#com-addForm textarea[name="'+i+'"]').val(text);
						continue;
					}else if(i=='clearDate'){
                        text=text==null?'':(new Date(text)).format('yyyy-MM-dd hh:mm:ss');
					}
					$('#com-addForm input[name="'+i+'"]').val(text);
				}
				if(ret.introduceTxt!=null){
					productInfoUpdate.introduceUE.ready(function() {
						productInfoUpdate.introduceUE.setContent(ret.introduceTxt);
	                });
				}
				if(ret.incomeTxt!=null){
					productInfoUpdate.incomeUE.ready(function() {
						productInfoUpdate.incomeUE.setContent(ret.incomeTxt);
	                });
				}
				if(ret.riskctrlTxt!=null){
					productInfoUpdate.riskctrlUE.ready(function() {
						productInfoUpdate.riskctrlUE.setContent(ret.riskctrlTxt);
	                });
				}
			}
		};
		sendApiNoLoad(url, params, cb, 'POST');
	},
	
	init:function(){
		productInfoUpdate.startEvent();
	}
}
$(document).ready(function() {
	productInfoUpdate.init();
});
function submitForm(){
	comValidform.submitForm();
	return returnStatus;
}